package com.yonghui.summer.po;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.List;

/**
 * @auther yangchuan
 * @date 2021-03-26 21:17
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SqlParams {
    private String sql;
    private List<Object> params;

    public Object[] getSqlParams() {
        if(params == null){
            return null;
        }
        Object[] result = new Object[params.size()];
        int i = 0;
        for(Object param : params){
            if(param instanceof Collection){
                result[i++] = ((Collection)param).toArray();
            }else{
                result[i++] = param;
            }
        }

        return result;
    }
}
